using UnityEngine;
using QFramework;
//using System.Numerics;

namespace ProjectSurvivor
{
	public partial class Player : ViewController
	{
		public float Movementspeed = 5f;
		public static Player Default;
		void Awake()
		{
			Default = this;
		}
		void OnDestroy()
		{
			Default = null;
		}
		void Start()
		{
			// Code Here
			"Hello QFrameWork".LogInfo();

			HurtBox.OnTriggerEnter2DEvent((collider2D) =>
			{
				var hitBox = collider2D.GetComponent<HitBox>();
				if (hitBox)
				{
					if (hitBox.Owner.CompareTag("Enemy"))
					{
						Global.Hp.Value--;
						if (Global.Hp.Value <= 0)
						{
							AudioKit.PlaySound("Die");
							this.DestroyGameObjGracefully();
							//ResKit.Init();
							UIKit.OpenPanel<UIGameOverPanel>();
						}
						else
						{
							AudioKit.PlaySound("Hurt");
						}
					}
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}
		void Update()
		{
			var v = Input.GetAxisRaw("Vertical");
			var h = Input.GetAxisRaw("Horizontal");
			var targeVelocity = new Vector2(h, v).normalized * Movementspeed;

			SelfRigidbody2D.velocity = Vector2.Lerp(SelfRigidbody2D.velocity, targeVelocity, 1 - Mathf.Exp(-Time.deltaTime * 5));
		}
	}
}
